import { _decorator, Component, Contact2DType, PolygonCollider2D } from 'cc';
import { Player } from './playerData';
import { Monster } from './monsterData';
const { ccclass, property } = _decorator;
@ccclass('touchPlayer')
export class touchPlayer extends Component {

    start() {

        // 注册单个碰撞体的回调函数
        let collider = this.getComponent(PolygonCollider2D);
        if (collider) {
            
            collider.on(Contact2DType.BEGIN_CONTACT, this.onBeginContact, this);
            
        }
    }

    update(deltaTime: number) {

    }
    onBeginContact(self, other) {
        let monster = other.node.parent.getComponent(Monster);
        let player = self.node.getComponent(Player);

        player.health -= monster.atk;
        player.viewPlayerHealth();
        player.dieFun();

    }
}

